/**
 * @Description: api工具类
 * @author tao.xie
 * @date 2019-07-22 11:32
*/

import { ajaxAsync } from 'vue-xiaobu-utils'

// const busInfoPostUrl = isRouteHasDirection()
//   ? '/bus/homeStationWithDirection'
//   : '/bus/homeStation'

const busInfoPostUrl = '/bus/homeStation'
/**
 * 判断是否走有方向的附近站点协议
 * @returns {boolean}
 */
// function isRouteHasDirection() {
//   if (window.ROUTE_HAS_DIRECTION === false) {
//     return false
//   } else {
//     return true
//   }
// }

/**
 * 获取附近站点需要的数量
 * @returns {number[]}
 */
function getNearbySiteList() {
  return window.NEARBY_SITE_LIST ? window.NEARBY_SITE_LIST : [5, 5, 5, 5, 5]
}

/**
 * 获取附近站点
 * @returns {Promise<void>}
 */
async function getNeayByStationList(longitude = 0, latitude = 0) {
  let postData = {
    LONGITUDE: longitude + '',
    LATITUDE: latitude + '',
    COUNTS: getNearbySiteList()
  }
  return ajaxAsync(busInfoPostUrl, postData)
}

/**
 * 获取附近站点对应线路
 * @returns {Promise<void>}
 */
async function getNeayByRouteList(longitude = 0, latitude = 0, stationID) {
  let postData = {
    LONGITUDE: longitude + '',
    LATITUDE: latitude + '',
    IMPORT: stationID
  }
  return ajaxAsync('/bus/busBystation', postData)
}

export { getNeayByStationList, getNeayByRouteList }
